document.addEventListener('DOMContentLoaded', function () {
    const slides = document.querySelectorAll('#imgs a');
    const totalSlides = slides.length;
    let currentIndex = 0;

    // 显示当前幻灯片
    function showSlide(index) {
        const offset = -index * 100;
        document.querySelector('#imgs').style.transform = `translateX(${offset}%)`;

        // 更新焦点指示器
        document.querySelectorAll('.num').forEach((dot, i) => {
            dot.classList.toggle('focus', i === index);
        });
    }

    // 自动播放
    function autoPlay() {
        currentIndex = (currentIndex + 1) % totalSlides;
        showSlide(currentIndex);
    }

    setInterval(autoPlay, 3000);

    // 手动切换
    document.querySelector('.icon_l').addEventListener('click', function () {
        currentIndex = (currentIndex - 1 + totalSlides) % totalSlides;
        showSlide(currentIndex);
    });

    document.querySelector('.icon_r').addEventListener('click', function () {
        currentIndex = (currentIndex + 1) % totalSlides;
        showSlide(currentIndex);
    });

    // 焦点指示器点击切换
    document.querySelectorAll('.num').forEach((dot, index) => {
        dot.addEventListener('click', function () {
            currentIndex = index;
            showSlide(currentIndex);
        });
    });

    // 初始化显示第一张幻灯片
    showSlide(currentIndex);
});